package platform.zfcjmq;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import platform.common.CommonInfo;

public class NettyServer {

    public static void main(String[] args) {
        new NettyServer().bing(CommonInfo.port);
    }

    private void bing(int port) {
        // 配置服务段Nio县城组
        EventLoopGroup parent = new NioEventLoopGroup();
        EventLoopGroup child = new NioEventLoopGroup();
        try{
            ServerBootstrap bootstrap = new ServerBootstrap();
            bootstrap.group(parent,child)
                    .channel(NioServerSocketChannel.class) // 非阻塞模式
                    .option(ChannelOption.SO_BACKLOG,128)
                    .childHandler(new MyChannelInitializer());
            ChannelFuture f = bootstrap.bind(port).sync();
            System.out.println("启动");
            f.channel().closeFuture().sync();
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            child.shutdownGracefully();
            parent.shutdownGracefully();
        }


    }
}
